package com.jing.product.controller;

import com.jing.common.core.domain.R;
import com.jing.common.core.web.controller.BaseController;
import com.jing.common.core.web.page.TableDataInfo;
import com.jing.product.domain.po.Brand;
import com.jing.product.domain.vo.BrandVO;
import com.jing.product.domain.vo.ProductAttributeCategoryVO;
import com.jing.product.service.BrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author：HaoYunde
 * @Package：com.jing.controller
 * @Project：Jing
 * @name：ProductController
 * @Date：2024/5/23 11:20
 */
@RestController
@RequestMapping("/brand")
@Validated
@Api(tags = "品牌表")
public class BrandController extends BaseController {
    @Autowired
    private BrandService brandService;
    /**
     * 查询品牌列表
     * @return
     */
    @GetMapping("/findBrandList")
    @ApiOperation(value = "查询品牌列表")
    public R findBrandList(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                           @RequestParam(required = false, defaultValue = "10") Integer pageSize,
                           @RequestParam(required = false) String name){
        startPage();
        List<Brand> list=brandService.findBrandList(name);
        TableDataInfo dataTable = getDataTable(list);
        return R.ok(dataTable);
    }


    /**
     * 删除品牌表
     * @param id
     * @return
     */
    @PostMapping("/delect")
    @ApiOperation(value = "删除品牌表")
    public R delect(@Valid @RequestParam Integer id){
        brandService.delect(id);
        return R.ok();
    }


    /**
     * 添加品牌表
     * @param brand
     * @return
     */
    @PostMapping("add")
    @ApiOperation(value = "添加品牌表")
    public R add(@RequestBody @Valid Brand brand){
        brandService.add(brand);
        return R.ok();
    }

    /**
     * 修改品牌表
     * @param brand
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改品牌表")
    public R update(@RequestBody @Valid Brand brand){
        brandService.update(brand);
        return R.ok();
    }


    /**
     * 修改品牌制造商
     * @param id
     * @param factoryStatus
     * @return
     */
    @GetMapping("/updateFactoryStatus")
    @ApiOperation(value = "修改品牌制造商")
    public R updateFactoryStatus(@Valid @RequestParam Integer id,@RequestParam Integer factoryStatus){
        brandService.updateFactoryStatus(id,factoryStatus);
        return R.ok("修改品牌制造商成功");
    }


    /**
     * 修改品牌是否显示
     * @param id
     * @param showStatus
     * @return
     */
    @GetMapping("/updateShowStatus")
    @ApiOperation(value = "修改品牌是否显示")
    public R updateShowStatus(@Valid @RequestParam Integer id,@RequestParam Integer showStatus){
        brandService.updateShowStatus(id,showStatus);
        return R.ok("修改品牌是否显示成功");
    }



    @GetMapping("/findALlBrand")
    @ApiOperation(value = "品牌下拉框")
    public R findALlBrand(){
        List<BrandVO> list= brandService.findALlBrand();
        return R.ok(list);
    }

}
